// pages/authorize/index.js
var app = getApp();
var md5 = require('../../utils/md5.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mone:[],
    page: 1,
    page_count: 10,
    keyword: '',
    loadmore: true
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    that.getMoneyDetailed();
  },
  getMoneyDetailed: function () {
    var that = this;
    var service = 'User.GetMoneyDetailedType'
    var user_id = wx.getStorageSync('user_id');
    var open_id = wx.getStorageSync('openid');
    var type = 3;
    var page = that.data.page
    var page_count = that.data.page_count
    var sign = md5.md5(open_id + page + page_count + service + type + user_id);
    wx.request({
      url: app.globalData.apiUrl + '?service=' + service,
      header: {
        'Content-Type': 'json'
      },
      data: {
        sign: sign,
        user_id: user_id,
        open_id: open_id,
        type: type,
        page: page,
        page_count: page_count
      },
      success: function (res) {
        var mone = that.data.mone.concat(res.data.data.info)
        that.setData({
          mone: mone
        });
        wx.hideLoading()
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  },
  /**
  * 页面上拉触底事件的处理函数
  */
  onReachBottom: function () {
    if (this.data.keyword == '') {
      if (this.data.loadmore) {
        var page = Number(this.data.page) + Number(1);
        console.log(page)
        this.setData({
          page: page
        });
        this.getMoneyDetailed()
      } else {
        wx.GetMoneyDetailed({
          title: '暂无更多'
        })
      }
    }
  }
})